﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace SampleIntermediateASPExam2
{
    public partial class Tours : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void EditTour(object sender, ListViewEditEventArgs args)
        {

        }

        protected void FacilitiesCheckBoxList_OnDataBound(object sender, EventArgs args)
        {
            using (TravelAgencyDatabaseEntities context = new TravelAgencyDatabaseEntities())
            {

                CheckBoxList checkBoxList = (CheckBoxList)sender;

                //object somOv = checkBoxList.Parent.Parent.Parent;
                int tourID = int.Parse((this.ToursListView.EditItem.FindControl("TourIDLabel") as Label).Text);

                Tour tour = context.Tours.FirstOrDefault(t => t.TourID == tourID);
                List<int> facilititesList = (from f in tour.Facilities
                                             select f.FacilityID).ToList();


                foreach (ListItem li in checkBoxList.Items)
                {

                    if (facilititesList.Contains(int.Parse(li.Value)))
                    {
                        li.Selected = true;
                    }
                }
            }
        }

    }
}